package com.hjx.movie.core.system.controller.admin;

import com.hjx.movie.common.utils.Result;
import com.hjx.movie.common.utils.ResultType;
import com.hjx.movie.core.system.service.admin.IOrderItemService;
import com.hjx.movie.persistence.system.model.IvyOrderItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2021/2/15 - 15:13
 */
@Slf4j
@RestController
@RequestMapping("/orderItem")
public class OrderItemController {

    @Resource
    private IOrderItemService orderItemService;

    @GetMapping("/findAll")
    public Result findAllOrderItem(){
        List<IvyOrderItem> allOrderItem = orderItemService.findAll();
        return Result.success(allOrderItem);
    }



    @PostMapping("/add")
    public Result addOrderItem(@RequestBody @Valid IvyOrderItem orderItem){
        log.debug("新增订单项方法接收到的入参为:{}",orderItem);
        if (orderItemService.addOrderItem(orderItem)) {
            return Result.success("新增订单项成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"新增订单项失败,入参不符合规则,请检查入参");
    }

    @PostMapping("/update")
    public Result updateOrderItem(@RequestBody @Valid IvyOrderItem orderItem){
        log.debug("修改订单项方法接收到的入参为:{}",orderItem);
        if (orderItemService.updateOrderItem(orderItem)) {
            return Result.success("修改订单项成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"修改订单项失败,入参不符合规则,请检查入参");
    }

    @GetMapping("/delete")
    public Result deleteOrderItemById(@RequestParam("orderItemId") Long orderItemId){
        log.debug("删除订单项方法接收到的入参为:{}",orderItemId);
        if (orderItemService.deleteOrderItem(orderItemId)) {
            return Result.success("删除订单项成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"删除订单项失败,入参不符合规则,请检查入参");
    }
}
